package com.open4cn.simulator.answer.datacolor;

import com.open4cn.simulator.core.answer.AbstractAnswer;
import com.open4cn.simulator.core.answer.AnswerModeEnum;
import com.open4cn.simulator.core.answer.AnswerResponse;
import com.open4cn.simulator.core.ext.DataColorStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description 绿板校正
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-04 19:23
 */
public class UV100Greenboard1000Answer extends AbstractAnswer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public UV100Greenboard1000Answer() {
        super("UV100Greenboard1000", AnswerModeEnum.SUCCESS);
    }

    public AnswerResponse answer(DataColorStatus dataColorStatus, String instruction) {
        if (!AnswerModeEnum.FAIL.equals(getAnswerMode())) {
            getActions().forEach(action -> {
                action.action(dataColorStatus, instruction);
            });
        }
        AnswerResponse response = getAnswer(dataColorStatus);
        return response;
    }

    /**
     * 获取应答结果
     *
     * @param dataColorStatus
     * @return
     */
    private AnswerResponse getAnswer(DataColorStatus dataColorStatus) {
        switch (getAnswerMode()) {
            case SUCCESS:
                return AnswerResponse.success(success(dataColorStatus));
            case FAIL:
                return AnswerResponse.fail(fail(dataColorStatus));
            case RANDOM:
                return AnswerResponse.success(random(dataColorStatus));
            case LOOP:
                return AnswerResponse.success(getLoop());
            case INPUT:
                Object input = pollInput();
                if (null != input) {
                    return AnswerResponse.success(input);
                }
            default:
                return AnswerResponse.success(success(dataColorStatus));
        }
    }


    /**
     * 成功应答
     * *IAR000x0xx1xxxxs2.000479 A0002C 11081000000000000000000.0000-01859.9747-03679.1714001811.9016-01005.7389000742.2866000071.7631000015.0000000000.0008000001.000004000048.0000000052.0000000048.0000000048.0000                                                                                        000064.3100000000.0000000000000000000064.9200000132.2900202110281034000000.0000000000.0000000000000000000000.0000000000.0000000000000000xx
     * 040.219,042.185,043.501,044.461,045.208,
     * 045.696,046.299,047.257,048.615,050.591,
     * 053.486,056.809,061.437,066.484,071.315,
     * 074.891,076.248,075.906,074.392,072.395,
     * 070.298,068.073,066.161,064.340,063.060,
     * 061.912,061.089,060.528,060.201,060.303,
     * 060.781,061.670,062.494,063.038,064.188,
     * 000.000,000.000,000.000,000.000,000.000,
     * 9B14:
     *
     * @param dataColorStatus
     * @return
     */
    private Object success(DataColorStatus dataColorStatus) {
        StringBuilder builder = new StringBuilder();
        builder.append("*")
                .append(dataColorStatus.getCurrentSpecularGloss().getCode())
                .append(dataColorStatus.getCurrentAperture().name())
                .append("R")
                .append(dataColorStatus.getCurrentUV().getCode())
                .append("x0xx1xxxxs2.000479 A0002C 11081000000000000000000.0000-01859.9747-03679.1714001811.9016-01005.7389000742.2866000071.7631000015.0000000000.0008000001.000004000048.0000000052.0000000048.0000000048.0000                                                                                        000064.3100000000.0000000000000000000064.9200000132.2900202110281034000000.0000000000.0000000000000000000000.0000000000.0000000000000000xx")
                .append("\r\n");
        builder.append("040.219,042.185,043.501,044.461,045.208,").append("\r\n");
        builder.append("045.696,046.299,047.257,048.615,050.591,").append("\r\n");
        builder.append("053.486,056.809,061.437,066.484,071.315,").append("\r\n");
        builder.append("074.891,076.248,075.906,074.392,072.395,").append("\r\n");
        builder.append("070.298,068.073,066.161,064.340,063.060,").append("\r\n");
        builder.append("061.912,061.089,060.528,060.201,060.303,").append("\r\n");
        builder.append("060.781,061.670,062.494,063.038,064.188,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("9B14:").append("\r\n");
        return builder.toString();
    }


    /**
     * 失败应答
     * *IAR000x0Ex1xxxxs2.000479 A0002C 11081000000000000000000.0000-01859.9747-03679.1714001811.9016-01005.7389000742.2866000071.7631000015.0000000000.0008000001.000004000048.0000000052.0000000048.0000000048.0000                                                                                        000064.3100000000.0000000000000000000064.9200000132.2900202110281034000000.0000000000.0000000000000000000000.0000000000.0000000000000000xx
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 000.000,000.000,000.000,000.000,000.000,
     * 9B14:
     *
     * @param dataColorStatus
     * @return
     */
    private Object fail(DataColorStatus dataColorStatus) {
        StringBuilder builder = new StringBuilder();
        builder.append("*")
                .append(dataColorStatus.getCurrentSpecularGloss().getCode())
                .append(dataColorStatus.getCurrentAperture().name())
                .append("R")
                .append(dataColorStatus.getCurrentUV().getCode())
                .append("x0Ex1xxxxs2.000479 A0002C 11081000000000000000000.0000-01859.9747-03679.1714001811.9016-01005.7389000742.2866000071.7631000015.0000000000.0008000001.000004000048.0000000052.0000000048.0000000048.0000                                                                                        000064.3100000000.0000000000000000000064.9200000132.2900202110281034000000.0000000000.0000000000000000000000.0000000000.0000000000000000xx")
                .append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("000.000,000.000,000.000,000.000,000.000,").append("\r\n");
        builder.append("9B14:").append("\r\n");
        return builder.toString();
    }


    /**
     * 随机反射率
     *
     * @param dataColorStatus
     * @return
     */
    private Object random(DataColorStatus dataColorStatus) {
        return success(dataColorStatus);
    }

}
